package com.jack.payment.constant.enums;


import com.jack.payment.entity.common.BusinessException;
import com.jack.payment.util.common.StringUtil;

public enum TimeEnum {
    YEAR(1, "year"),                // 年
    QUARTER(2, "quarter"),          // 季
    MONTH(3,"month"),               // 月
    WEEK(4, "week"),                // 周
    DAY(5, "date"),                  // 天
    HOUR(6,"hour"),                 // 小时
    MINUTE(7,"minute"),             // 分钟
    SECOND(8,"second")              // 秒
    ;

    private Integer value;
    private String timeType;

    TimeEnum(Integer value, String timeType) {
        this.value = value;
        this.timeType = timeType;
    }

    public Integer getValue() {
        return value;
    }

    public String getTimeType() {
        return timeType;
    }
    // 根据值数值类型
    public static TimeEnum getValueTimeEnum(Integer value) {
        if (value != null) {
            for (TimeEnum timeEnum : TimeEnum.values()) {
                if (timeEnum.getValue().equals(value)) {
                    return timeEnum;
                }
            }
        }
        return TimeEnum.MONTH;
    }
    // 根据所给字符
    public static TimeEnum getTimeTypeEnum(String timeType) throws BusinessException {
        if (!StringUtil.isEmpty(timeType)) {
            for (TimeEnum timeEnum : TimeEnum.values()) {
                if (timeEnum.getTimeType().equals(timeType)) {
                    return timeEnum;
                }
            }
        }
        throw new BusinessException();
    }
}
